package com.example.baseweb.dto;

import com.example.baseweb.common.OrderStatusEnum;
import com.example.baseweb.entity.OrderInfo;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;

@Data
public class OrderInfoDTO {
    private Long id;
    private String orderNo;
    private Long userId;
    private String userName;
    private LocalDateTime orderDate;
    private LocalDate menuDate;
    private String mealType;
    private String dishList;
    private BigDecimal totalAmount;
    private String status;
    private String statusText; // 中文状态
    private String paymentMethod;
    private LocalDateTime paymentTime;
    private LocalDateTime refundTime;
    private String remark;
    private LocalDateTime createTime;
    private LocalDateTime updateTime;
    
    public static OrderInfoDTO fromEntity(OrderInfo orderInfo) {
        if (orderInfo == null) return null;
        
        OrderInfoDTO dto = new OrderInfoDTO();
        dto.setId(orderInfo.getId());
        dto.setOrderNo(orderInfo.getOrderNo());
        dto.setUserId(orderInfo.getUserId());
        dto.setUserName(orderInfo.getUserName());
        dto.setOrderDate(orderInfo.getOrderDate());
        dto.setMenuDate(orderInfo.getMenuDate());
        dto.setMealType(orderInfo.getMealType());
        dto.setDishList(orderInfo.getDishList());
        dto.setTotalAmount(orderInfo.getTotalAmount());
        dto.setStatus(orderInfo.getStatus());
        dto.setStatusText(OrderStatusEnum.getStatusText(orderInfo.getStatus())); // 设置中文状态
        dto.setPaymentMethod(orderInfo.getPaymentMethod());
        dto.setPaymentTime(orderInfo.getPaymentTime());
        dto.setRefundTime(orderInfo.getRefundTime());
        dto.setRemark(orderInfo.getRemark());
        dto.setCreateTime(orderInfo.getCreateTime());
        dto.setUpdateTime(orderInfo.getUpdateTime());
        
        return dto;
    }
} 